Repository navigation
Strictness hardening: strict mypy everywhere, wider ruff, strict pytest, pre-commit, CI checks - #5
Merged
Merged
Conversation
…access filterwarnings=error exposed two test bugs: test_upload_passes_delimiter sent a real request to api.reportnet.europa.eu (the pre-upload schema check was not faked; the library skips the check when the schema is unreadable, so the test still passed), and a test fake left uploaded files open. An autouse fixture now fails any test that opens a non-loopback connection.
…d its safe auto-fixes Ignored with reasons in pyproject.toml: PLR0913 (resource methods mirror endpoints), PLC0415 (lazy optional pandas), FBT001/002 (public API), PT018/SIM117 (style churn). The remaining findings are fixed by hand in the following commits.
…-After values A caller sleeping for retry_after would wait forever on 'inf'. It now returns None for non-finite values, like the retry policy's own Retry-After parsing.
pathlib instead of os.path/open where equivalent (kept os.path with a coded noqa where abspath's semantics matter); named constants for magic numbers; explicit check instead of an assert; keyword-only flag in jobs._wait; coded noqa with a reason for NaN self-comparisons and the token_scheme default. Complexity rules (PLR0911/0912/0915) are ignored in config with the reason.
pytest.raises now pins each expected message (PT011); raw match patterns; tuple parametrize names; pathlib; explicit check instead of an assert in generate_docs; coded noqa with a reason for fixed-argv subprocess calls, scheme-name 'passwords' and the backend's typographic quote in a test.
… None (mypy redundant-expr)
files = package + tests + scripts + tools; warn_unreachable, ignore-without-code, redundant-expr, truthy-bool, possibly-undefined. Package: typed the frame walk in caller_stacklevel (drops a type: ignore); coded ignore for a mypy false positive (bool is numbers.Integral at runtime). Scripts/tools: generic dict args, Operation.path_fstring as a real method (drops a type: ignore), isinstance narrowing for Streamlit's upload object. numpy stubs are skipped (3.12 syntax under python_version 3.11). tests.* has a TEMPORARY untyped-defs override; the rest of the test errors are fixed next.
Fake API errors carry a real request/response (tests/helpers.api_error) instead of None; named fakes instead of 'lambda: list.append(...) or value'; calls to None-returning methods are no longer asserted 'is None' (mypy now guarantees it); monkeypatch targets by path instead of through easy's private imports; generic dict arguments.
Test functions return None; pytest fixtures and parametrize arguments are typed; fakes that only raise are NoReturn; helpers have real signatures (_error takes json/text explicitly, _event a status). Duck-typed fake clients are cast to ReportnetClient with a comment, and replaced methods go through monkeypatch.setattr.
…hape) Same fields, equality, hashing, pickling and replace(); instances no longer have a __dict__ or weakref support (frozen already forbade new attributes).
…e project, generated-code freshness .pre-commit-config.yaml runs the locked ruff and mypy through uv. CI adds 'ruff format --check', runs mypy with the configured files, and a 'generated' job that reruns the model/resource/docs generators and fails on any diff. Contributor docs list the new commands.
…atch, _Shape)" This reverts commit e30196f.
…pback address allowed) Codex review: the guard only covered socket.connect and rejected loopback addresses such as 127.0.0.2. Now connect, connect_ex and sendto refuse non-loopback addresses, getaddrinfo refuses non-local host names, and any 127.0.0.0/8 or ::1 address and *.localhost name counts as local. Covered by tests/test_no_network_guard.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens the repo for strictness and correctness. No intended behaviour change except the bug fix below.
Before / after
mypy --strict(package, tests, scripts, tools)pytest -W errorfilterwarnings = error,--strict-markers --strict-config)Bugs found
TooManyRequestsError.retry_afterreturnedinf/nanfor suchRetry-Aftervalues; it now returnsNone, like the retry policy (new tests fail without the fix).test_upload_passes_delimitersent a real request toapi.reportnet.europa.eu(the schema check wasn't faked). An autouse fixture now fails any test that connects to, sends UDP to, or resolves a non-loopback host (tests/test_no_network_guard.py).Other changes
return None; noNonefilter for all-required query params (regenerated in separate commits).slots=Truecommit was reverted after review: it changed class-level attribute access on public classes such asRetryPolicy.retries.).pre-commit-config.yaml(locked ruff + mypy via uv); CI addsruff format --check, mypy on the whole project, and ageneratedjob that reruns the generators and fails on any diff.Still non-strict (with reasons in
pyproject.toml)PLR0913,PLC0415,FBT001/002, complexity rules,PT018/SIM117; 27Anyannotations (JSON payloads, forwarded kwargs). TypedDict/Literal on the public API and keyword-only booleans are left for a 0.2.0 decision (they would break callers' type checks).Local checks
Reviewed with Codex; the download/export-fallback findings (pre-existing or from 0.1.2) are fixed in a separate PR.